<?php
	if (session_status() == PHP_SESSION_NONE) {
		function __autoload($class_name){
			$dirs = array(
				'../Factories/',
				'../cntrlr/',
				'../mdl/',
				'../mdl/Delete/',
				'../mdl/Select/',
				'../mdl/Update/',
				'../mdl/Insert/',
				'../'
			);
			foreach($dirs as $dir){
				if(file_exists($dir.$class_name . '.php')){
					require_once($dir.$class_name . '.php');
					return;
				}
			}
			throw new BadFunctionCallException("No such Object file");
		}

		session_start();
	}
	if (isset($_GET["quantity"]) && isset($_GET["name"])){
		$factory = Factories::Init();
		$db      = $factory->databaseObject("select", "stocks");
		$stock = $db-> rowByName($_GET["name"]);
		$stock->setOrderQuantity($_GET["quantity"]);
		$_SESSION["order"]->addStock($stock);
	} elseif (isset($_GET["quantity"]) && isset($_GET["delete"])){
		$factory = Factories::Init();
		$db      = $factory->databaseObject("select", "stocks");
		$stock = $db-> rowByName($_GET["delete"]);
		$stock->setOrderQuantity($_GET["quantity"]);
		$_SESSION["order"]->deleteStock($stock);
	} elseif (isset($_GET["quantity"]) && isset($_GET["update"])){
		$factory = Factories::Init();
		$db      = $factory->databaseObject("select", "stocks");
		$stock = $db-> rowByName($_GET["update"]);
		$stock->setOrderQuantity($_GET["quantity"]);
		$_SESSION["order"]->updateInSum($stock);
	} elseif (isset($_GET["clear"])){
		$_SESSION["order"]->clear();
	}
	require_once("../vw/userside/frontPageCartView.php");
?>
